package LeetCode._02算法基础.day04双指针;

import java.util.Arrays;
import java.util.Stack;
import java.util.function.Function;

/**
 * @author 挚爱之夕
 * @version 1.0
 * @implSpec LeetCode._02算法基础.day04双指针
 * @since 2022 - 08 - 31 - 8:19
 */
public class Test {
    public boolean backspaceCompare(String s, String t) {
        return getPlainStr(s).equals(getPlainStr(t));
    }
    public String getPlainStr(String s){
        Stack<Character> stack = new Stack<>();
        for(int i = 0; i < s.length(); i++){
            char c = s.charAt(i);
            if(c == '#'){
                if(!stack.empty())
                    stack.pop();
            }else{
                stack.push(c);
            }
        }
        return Arrays.toString(stack.toArray());
    }

    public static void main(String[] args) {
        boolean res = new Test().backspaceCompare("ab#c", "ad#c");
        System.out.println(res);
    }
}
